package com.sky.service.impl;

import com.sky.entity.User;
import com.sky.mapper.UserMapper;
import com.sky.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;

@Slf4j
@Service
public class UserServiceImpl implements UserService {
	@Autowired
	UserMapper userMapper;

	@Override
	public User userByOpenId(String openId) {
		log.info("查询openId:{}的用户");
		User user =  userMapper.userByOpenId(openId);
		log.info("查询结果{}",user);
		return user;
	}

	@Override
	@Transactional
	public void insert(User user) {
		//填充默认字段
		user.setCreateTime(LocalDateTime.now());

		userMapper.insert(user);
		log.info("新增用户:{}",user);
	}
}
